/**
 * Created by sun on 2016/9/9.
 */
define(function (require) {
    var app = require('/../js/app');
    require('ui-table');
    var datepicker = require('datepicker');
    app.useModule("ui.table");

    app.controller('client_contractCtrl', ['$scope','$http','$filter',function ($scope, $http,$filter){

        datepicker($scope);
        $scope.ctrlScope=$scope;
        //列表
        $scope.orderParams = {
            url: "/admin/contracts/listContracts",
            ajax:{orderName:'endTime',orderWay:'desc'}
        };

        //搜索
        $scope.search = function() {
            $scope.ctrlScope.itemsearch.beginDateTime=$scope.ctrlScope.itemsearch.beginDateTimeX;

            $scope.ctrlScope.itemsearch.beginDateTime=$filter('date')($scope.ctrlScope.itemsearch.beginDateTimeX,'yyyy-MM-dd');

            $scope.ctrlScope.itemsearch.endDateTime=$scope.ctrlScope.itemsearch.endDateTimeX;

            $scope.ctrlScope.itemsearch.endDateTime=$filter('date')($scope.ctrlScope.itemsearch.endDateTimeX,'yyyy-MM-dd');
            $scope.orderParams.ajaxParam=$scope.ctrlScope.itemsearch;

            $scope.orderParams.reload();
        };

        //搜索重置
        $scope.reset=function(){
            $scope.ctrlScope.itemsearch = {};
            $scope.search();

        };

        //下载
        $scope.download= function (url) {
            window.open(url);
        };


        //排序
        $scope.onOff=true;
        $scope.order= function (name) {
            if($scope.onOff){
                $scope.orderParams.ajaxParam={orderName:name,orderWay:'desc'};
                $scope.orderParams.reload();
                $scope.onOff=false;
            }else if(!$scope.onOff){
                $scope.orderParams.ajaxParam={orderName:name,orderWay:'Asc'};
                $scope.orderParams.reload();
                $scope.onOff=true;
            }

        };


        //明细
        $scope.moreData=false;
        $scope.detailData=true;
        $scope.DetailData= function () {
            $scope.moreData=true;
            $scope.detailData=false;
        };
        $scope.hideDetailData= function () {
            $scope.moreData=false;
            $scope.detailData=true;
        }


    }]);


});